<template>
  <div class="">
    <div class="page-filter mb10 fl">
      <el-form ref="filter" :model="filter" label-width="0">
        <el-form-item class="mr10 mb5 fl">
          <el-input v-model="filter.nickname" placeholder="姓名" size="small" clearable />
        </el-form-item>
        <el-form-item class="mr10 mb5 fl" style="width: 300px">
          <el-button size="small" @click="app.resetFields($refs['filter'].$parent,'filter')">清 空</el-button>
          <el-button type="primary" size="small" @click="getList">查 询</el-button>
          <el-button
            type="primary"
            size="small"
            @click="handleDialog({
              dTitle: '新增员工',
              dType: 'add',
              dField: dField
            })"
          >新 增</el-button>
        </el-form-item>
      </el-form>
    </div>
    <el-table v-loading="app.loading" class="search-table" :data="list" border fit highlight-current-row style="width: 100%;">
      <el-table-column label="序号" align="center" width="56px">
        <template slot-scope="{$index}">
          {{ $index + 1 }}
        </template>
      </el-table-column>
      <el-table-column label="姓名" width="120px" prop="nickname" />
      <el-table-column label="学历" width="110px" prop="education" />
      <el-table-column label="部门" width="150px" prop="dept_name" />
      <el-table-column label="职位" width="150px" prop="pos_name" />
      <el-table-column label="性别" align="center" width="80px" :formatter="formatter" />
      <el-table-column label="出生日期" align="center" width="110px" prop="birthday" />
      <el-table-column label="身份证号" align="center" width="190px" prop="card" />
      <el-table-column label="入职日期" align="center" width="110px" prop="induction_time" />
      <el-table-column label="手机号码" align="center" width="120px" prop="phone" />
      <el-table-column label="状态" align="center" width="80px" :formatter="formatterState" />
      <el-table-column label="备注" min-width="260px" prop="remark" />
      <el-table-column label="操作" align="center" width="90px" fixed="right">
        <template slot-scope="{row}">
          <el-dropdown>
            <el-button type="primary" size="mini">
              操作<i class="el-icon-arrow-down el-icon--right" />
            </el-button>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item
                @click.native="handleDialog({...row, ...
                {dTitle: '编辑员工', dType: 'edit', dField: dField}})"
              >
                编 辑
              </el-dropdown-item>
              <el-dropdown-item @click.native="handleQuit(row)">离 职</el-dropdown-item>
              <el-dropdown-item
                @click.native="files({e_id: row.id, type: '',
                                      db_type: 'logc_staff_archives'})"
              >
                合 同
              </el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </template>
      </el-table-column>
    </el-table>
    <pagination v-show="filter.pageAll>0" :total="filter.pageAll" :page.sync="filter.pageCurrent" :limit.sync="filter.pageNumber" @pagination="getList" />
    <Dialog ref="dialog" :get-data="getList" :info="dialog" />
    <Cos ref="cos" :info="dialog" />
  </div>
</template>

<script>
import page from '@/utils/page'
import { queryStaffs, staffQuit } from '@/api/staff'
import Dialog from './components/staff-dialog'

export default {
  name: '',
  components: { Dialog },
  extends: page,
  props: {
    reqList: {
      default: queryStaffs,
      type: Function
    }
  },
  data() {
    return {
      parameter: { 'state': 'duty' },
      dField: ['id', 'nickname', 'phone', 'sex', 'birthday', 'card', 'induction_time', 'remark', 'state', 'education']
    }
  },
  created() {
    this.getList()
  },
  methods: {
    formatter(e) {
      let sex = '-'
      switch (e.sex) {
        case 1:
          sex = '男'
          break
        case 2:
          sex = '女'
          break
        default:
          break
      }
      return sex
    },
    formatterState(e) {
      let state = '-'
      switch (e.state) {
        case 0:
          state = '未转正'
          break
        case 1:
          state = '已转正'
          break
        case 2:
          state = '已离职'
          break
        default:
          break
      }
      return state
    },
    handleQuit(e) {
      this.$confirm('此操作将使员工离职，是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(async() => {
        staffQuit({
          id: e['id']
        }).then(response => {
          this.getList()
          this.$message.success('操作成功')
        })
      })
    }
  }
}
</script>
